#ifndef _SQLITEDATASOURCE_H
#define	_SQLITEDATASOURCE_H

#include <list>
#include <string>
#include <vector>
#include <sqlite3.h>
#include "DataSource.h"
#include "DataSourceException.h"
#include "genealogy_tree/GenealogyTree.h"
#include "genealogy_tree/Person.h"

namespace etu {
namespace db {

using etu::common::ParseException;
using etu::genealogy_tree::GenealogyTree;
using etu::genealogy_tree::Person;

class SqliteDataSource : public DataSource {

    sqlite3* connection;
    
public:
    SqliteDataSource(const std::string& dbUrl) throw(DataSourceException);
    SqliteDataSource(const SqliteDataSource& orig);
    virtual ~SqliteDataSource();
    virtual bool isGenealogyTreeExists(const std::string& name)
        throw(DataSourceException);
    virtual GenealogyTree* getGenealogyTree(const std::string& name)
        throw(DataSourceException);
    virtual std::list<std::string>* getGenealogyTreeNames()
        throw(DataSourceException);
    virtual void addGenealogyTree(const std::string& name, const GenealogyTree& tree)
        throw(DataSourceException);
    virtual void deleteGenealogyTree(const std::string& name)
        throw(DataSourceException);
    virtual void updateGenealogyTree(const std::string& name,
        const GenealogyTree& tree) throw(DataSourceException);

    virtual bool isPhotoExists(const Person& person) throw(DataSourceException);
    virtual Photo* getPhoto(const Person& person) throw(DataSourceException);
    virtual void addPhoto(Person* person, const Photo& photo) throw(DataSourceException);
    virtual void deletePhoto(const Person& person) throw(DataSourceException);
    
private:
    std::vector<std::vector<std::string> > executeQuery(const std::string& query)
            throw(DataSourceException);
    void executeUpdate(const std::string& query) throw(DataSourceException);
    void initDb() throw(DataSourceException);
};

}
}

#endif	/* _SQLITEDATASOURCE_H */

